package com.chen.base.module.base.dto;

import lombok.Data;
import lombok.ToString;

/**
 * @Title: manager-spring-mvc-hb
 * @Description: to do
 * @Author: chenjiwei
 * @Date: 2020-11-15 15:37
 * @Version: 1.0.0
 */
@Data
@ToString
public class Response<T> {
    private String code;
    private String message;
    private T data;

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public Response(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public Response(ResponseStatus code, String message, T data){
        this(code.getCode(), message, data);
    }

    public Response(ResponseStatus code, T data){
        this(code.getCode(), code.getMessage(), data);
    }

    public static Response success(){
        return new Response(ResponseStatus.SUCCESS, null);
    }

    public static Response success(String message){
        return new Response(ResponseStatus.SUCCESS, message, null);
    }

    public static <T> Response success(String message, T data){
        return new Response(ResponseStatus.SUCCESS, message, data);
    }

    public static Response fail(){
        return new Response(ResponseStatus.FAIL, null);
    }

    public static Response fail(String message){
        return new Response(ResponseStatus.FAIL, message, null);
    }

    public static Response fail(String code, String message){
        return new Response(code, message, null);
    }

    public static <T> Response fail(String message, T data){
        return new Response(ResponseStatus.FAIL, message, data);
    }

    public static <T> Response fail(String code, String message, T data){
        return new Response(code, message, data);
    }
}
